<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
        }
        .switch-box{
            font-size: 12px;
            user-select: none;
        }
        .switch-box>span{
            font-size: 1.2em;
            vertical-align: middle;
            /* font-weight: bold; */
        }
        .switch-box>span.active{
            color: #409eff;
        }
        .switch-btn{
            vertical-align: middle;
            margin: 0px 0.5em;
            display: inline-block;
            /* 单位采用em */
            width: 4em;
            height: 2em;
            border-radius: 2em;
            cursor: pointer;
            background-color: #dcdfe6;
            box-shadow: 0 0 0.3em #999 inset;
            transition: all 400ms ease;
        }
        .switch-btn::after{
            content: "";
            display: inline-block;
            width: 2em;
            height: 2em;
            background-color: white;
            border-radius: 50%;
            transform: translate(0%,0%) scale(0.8);
            box-shadow: 0 0 0.3em #999;
            transition: all 400ms ease;
        }
        .switch-box input[type="checkbox"]{
            display: none;
        }
        .switch-box input[type="checkbox"]:checked + .switch-btn{
            background-color: #409eff;
            box-shadow: 0 0 0.3em #2c6fb1 inset;
        }
        .switch-box input[type="checkbox"]:checked + .switch-btn::after{
            transform: translate(100%,0%) scale(0.8);
        }
    </style>
</head>
<body>
    <div id="app">

        <label class="switch-box">
            <span v-bind:class=" switchState||'active' ">按年付费</span>
            <input type="checkbox" v-bind:checked="switchState" v-on:change="changeState( $event.target.checked )">
            <div class="switch-btn"></div>
            <span v-bind:class=" !switchState||'active' ">按月付费</span>
        </label>
        <br>
        <label class="switch-box" style="font-size: 20px;">
            <span v-bind:class=" switchState||'active' ">按年付费</span>
            <input type="checkbox" v-bind:checked="switchState" v-on:change="changeState( $event.target.checked )">
            <div class="switch-btn"></div>
            <span v-bind:class=" !switchState||'active' ">按月付费</span>
        </label>

    </div>
    <script type="module"> 
        import { createApp } from "../assets/vue3/vue.esm-browser.js";
        createApp({
            data(){
                return {
                    switchState:false
                }
            },
            methods:{
                changeState(state){
                    // console.log(state)
                    this.switchState = state;
                }
            }
        }).mount("#app")
    </script>
</body>
</html>